<template>
  <div id="contsainer"></div>
</template>
<script>
export default {
  data() {
    return {
      viewer: null
    }
  },
  mounted() {
    this.initCesium()
    this.render3dtiles(this.viewer)
  },
  methods: {
    initCesium() {
      this.viewer = new Cesium.Viewer('contsainer', {
        animation: false,
        baseLayerPicker: false,
        fullscreenButton: false,
        geocoder: false,
        homeButton: false,
        infoBox: false,
        sceneModePicker: false,
        navigationHelpButton: false,
        scene3DOnly: true,
        timeline: false,
        selectionIndicator: false, //是否显示选取指示器组件
        shouldAnimate: false, //自动播放动画控件
        shadows: true, //是否显示光照投射的阴影
        terrainShadows: Cesium.ShadowMode.RECEIVE_ONLY, //地质接收阴影
        sceneMode: Cesium.SceneMode.SCENE3D
      })
      this.viewer._cesiumWidget._creditContainer.style.display = 'none' //	去除版权信息
    },
    render3dtiles(viewer) {
      // Cesium.ExperimentalFeatures.enableModelExperimental = true;
      this.viewer.scene.primitives.add(new Cesium.Cesium3DTileset({
        url: 'http://localhost:8888/model/3dtiles/build/tileset.json',
        customShader: new Cesium.CustomShader({
          lightingModel: Cesium.LightingModel.PBR,
          //lightingModel: Cesium.LightingModel.UNLIT,
          fragmentShaderText: `
                                              void fragmentMain(FragmentInput fsInput, inout czm_modelMaterial material)
                                              {
                                                  material.diffuse = vec3(0.0, 0.0, 1.0);
                                                  material.diffuse.g = -fsInput.attributes.positionEC.z / 1.0e3;
                                              }
                                              `
        })
      })).readyPromise.then((tileset) => {
        this.viewer.zoomTo(tileset)
      })
    }
  }
}
</script>
<style scoped>
#contsainer {
  height: 100%;
  width: 100%;
  background-color: red;
}
</style>
